//
//  BankCardManageTableViewCell.m
//  FactorySale
//
//  Created by 主事丫环 on 2020/1/8.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "BankCardManageTableViewCell.h"

@implementation BankCardManageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setFrame:(CGRect)frame{
    frame.origin.x += 10;
    frame.origin.y += 10;
    frame.size.height -= 10;
    frame.size.width -= 20;
    [super setFrame:frame];
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        
        self.backgroundColor = [UIColor clearColor];
        
        UIView *bottomV = [[UIView alloc] init];
        bottomV.frame = CGRectMake(0, 0, KWIDTH-20, 140);
        bottomV.layer.cornerRadius = 5;
        bottomV.layer.masksToBounds = YES;
        [self.contentView addSubview:bottomV];
        //cell背景图片
        UIImageView *bgImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH-20, 130)];
        [bgImgV setImage:imgname(@"AddBankCardCellBg")];
        [bottomV addSubview:bgImgV];
      
        //是否默认 按钮图片
        UIButton *rightTopBtn = [[UIButton alloc] initWithFrame:CGRectMake(KWIDTH-50, 10, 25, 25)];
        [rightTopBtn addTarget:self action:@selector(rightTopBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [rightTopBtn setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
        [bottomV addSubview:rightTopBtn];
        self.rightTopBtn = rightTopBtn;
        
        
        //银行Logo背景图片
        UIView *bankLogoBg = [[UIView alloc] initWithFrame:CGRectMake(16, 18.5, 39, 39)];
        bankLogoBg.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
        bankLogoBg.layer.cornerRadius = 19.5;
        bankLogoBg.layer.masksToBounds = YES;
        [bottomV addSubview:bankLogoBg];
        //银行Logo图片
        UIImageView *logoImg = [[UIImageView alloc] initWithFrame:CGRectMake(3.5, 3.5, 32, 32)];
        logoImg.layer.cornerRadius = 16;
        logoImg.layer.masksToBounds = YES;
        [bankLogoBg addSubview:logoImg];
        self.logoImg = logoImg;
        //银行名字
        UILabel *bankNameLab = [[UILabel alloc] initWithFrame:CGRectMake(bankLogoBg.right +10, 18.5, KWIDTH/2, 15)];
        bankNameLab.font = FontSize(15);
        bankNameLab.textAlignment = NSTextAlignmentLeft;
        bankNameLab.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        [bottomV addSubview:bankNameLab];
        self.bankNameLab = bankNameLab;
        //卡片类型
        UILabel *cardTypeLab = [[UILabel alloc] initWithFrame:CGRectMake(bankLogoBg.right +10, bankNameLab.bottom +10, KWIDTH/2, 15)];
        cardTypeLab.text = @"储蓄卡";
        cardTypeLab.font = FontSize(14);
        cardTypeLab.textAlignment = NSTextAlignmentLeft;
        cardTypeLab.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        [bottomV addSubview:cardTypeLab];
        self.cardTypeLab = cardTypeLab;
        //银行卡账号
        UILabel *cardNumLab = [[UILabel alloc] initWithFrame:CGRectMake(bankLogoBg.right +10, cardTypeLab.bottom +23.5, KWIDTH-100, 18)];
        cardNumLab.font = FontSize(18);
        cardNumLab.textAlignment = NSTextAlignmentLeft;
        cardNumLab.textColor = [UIColor colorWithHexString:@"#1D876E"];
        [bottomV addSubview:cardNumLab];
        self.orderNumLab = cardNumLab;
                
    }
    return self;
}

//这是处理银行卡号明文字符串的方法，只需要将明文的银行卡号传入下面的API接口就行

-(NSString *)returnBankCard:(NSString *)BankCardStr
{
    NSString *formerStr = [BankCardStr substringToIndex:4];
    NSString *str1 = [BankCardStr stringByReplacingOccurrencesOfString:formerStr withString:@""];
    NSString *endStr = [BankCardStr substringFromIndex:BankCardStr.length-4];
    NSString *str2 = [str1 stringByReplacingOccurrencesOfString:endStr withString:@""];
    NSString *middleStr = [str2 stringByReplacingOccurrencesOfString:str2 withString:@"****"];
    NSString *CardNumberStr = [formerStr stringByAppendingFormat:@"%@%@",middleStr,endStr];
    return CardNumberStr;
}

-(void)refasf:(BankCardManageModel *)cardModel{
    if (cardModel) {
        _cardModel = cardModel;
        [self.logoImg sd_setImageWithURL:[NSURL URLWithString:cardModel.bank_log] placeholderImage:nil];
        self.bankNameLab.text = cardModel.bank_name;
        self.cardTypeLab.text = @"储蓄卡";
        //self.orderNumLab.text = cardModel.card_no;
        self.orderNumLab.text = [self returnBankCard:cardModel.card_no];

    }
}

- (void)rightTopBtnClick:(UIButton *)button {

    
  
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
